import numpy as np
import pandas as pd

# 读取你提供的CSV文件
df = pd.read_csv('insurance.csv')

# 通过调用describe()函数，得到数值型数据的描述性统计信息
print(df.describe(include=[np.number]))

# 按照费用（charges）排序，降序
df_sorted_desc = df.sort_values(by="charges", ascending=False)

# 按照费用（charges）排序，升序
df_sorted_asc = df.sort_values(by="charges", ascending=True)

# 获取前20个费用最多的记录
top_20_expensive = df_sorted_desc.head(20)

# 获取前20个费用最少的记录
top_20_cheapest = df_sorted_asc.head(20)
print("前20个费用最多的记录：\n", top_20_expensive)
print("\n前20个费用最少的记录：\n", top_20_cheapest)

# 对于分类数据，我们通常会对它的每一项内容进行计数统计
print("\nSex distribution:\n", df['sex'].value_counts())
print("\nSmoker distribution:\n", df['smoker'].value_counts())
print("\nRegion distribution:\n", df['region'].value_counts())